﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ivan_snake
{
    class GameController
    {
     
       

        public event EventHandler<SnakeKey > KeyPressed;

        protected virtual void OnKeyPressed(SnakeKey  key)
        {
            if (this.KeyPressed != null)
                this.KeyPressed(this,key);
               
        }

        public void ReadKey()
        {

            if (Console.KeyAvailable == true)
            {

                var key = Console.ReadKey().Key;

                switch (key)
                {
                    case ConsoleKey.RightArrow:
                        OnKeyPressed(SnakeKey.Right );
                        break;
                    case ConsoleKey.UpArrow:
                        OnKeyPressed(SnakeKey.Up);
                        break;
                    case ConsoleKey.DownArrow:
                        OnKeyPressed(SnakeKey.Down );
                        break;
                    case ConsoleKey.LeftArrow:
                        OnKeyPressed(SnakeKey.Left);
                        break;
                }
            }
            else
            {

            }
        }
    }



    public enum SnakeKey
    {
        Up,
        Down,
        Right,
        Left

    }
}
